package com.ruoyi.tzai.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tzai.domain.NewsContent;
import com.ruoyi.tzai.service.INewsContentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 资讯内容Controller
 * 
 * @author tzai
 * @date 2025-10-27
 */
@Api(tags = "资讯内容管理")
@RestController
@RequestMapping("/tzai/content")
public class NewsContentController extends BaseController
{
    @Autowired
    private INewsContentService newsContentService;

    /**
     * 查询资讯内容列表
     */
    @ApiOperation("查询资讯内容列表")
    @PreAuthorize("@ss.hasPermi('tzai:content:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewsContent newsContent)
    {
        startPage();
        List<NewsContent> list = newsContentService.selectNewsContentList(newsContent);
        return getDataTable(list);
    }

    /**
     * 导出资讯内容列表
     */
    @ApiOperation("导出资讯内容列表")
    @PreAuthorize("@ss.hasPermi('tzai:content:export')")
    @Log(title = "资讯内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewsContent newsContent)
    {
        List<NewsContent> list = newsContentService.selectNewsContentList(newsContent);
        ExcelUtil<NewsContent> util = new ExcelUtil<NewsContent>(NewsContent.class);
        util.exportExcel(response, list, "资讯内容数据");
    }

    /**
     * 获取资讯内容详细信息
     */
    @ApiOperation("获取资讯内容详细信息")
    @PreAuthorize("@ss.hasPermi('tzai:content:query')")
    @GetMapping(value = "/{contentId}")
    public AjaxResult getInfo(@PathVariable("contentId") Long contentId)
    {
        return success(newsContentService.selectNewsContentByContentId(contentId));
    }

    /**
     * 根据文章ID和语言获取资讯内容
     */
    @ApiOperation("根据文章ID和语言获取资讯内容")
    @GetMapping(value = "/article/{articleId}")
    public AjaxResult getByArticleId(@PathVariable("articleId") Long articleId, 
                                      @RequestParam(required = false, defaultValue = "cn") String language)
    {
        return success(newsContentService.selectNewsContentByArticleIdAndLanguage(articleId, language));
    }

    /**
     * 新增资讯内容
     */
    @ApiOperation("新增资讯内容")
    @PreAuthorize("@ss.hasPermi('tzai:content:add')")
    @Log(title = "资讯内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewsContent newsContent)
    {
        return toAjax(newsContentService.insertNewsContent(newsContent));
    }

    /**
     * 修改资讯内容
     */
    @ApiOperation("修改资讯内容")
    @PreAuthorize("@ss.hasPermi('tzai:content:edit')")
    @Log(title = "资讯内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewsContent newsContent)
    {
        return toAjax(newsContentService.updateNewsContent(newsContent));
    }

    /**
     * 删除资讯内容
     */
    @ApiOperation("删除资讯内容")
    @PreAuthorize("@ss.hasPermi('tzai:content:remove')")
    @Log(title = "资讯内容", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contentIds}")
    public AjaxResult remove(@PathVariable Long[] contentIds)
    {
        return toAjax(newsContentService.deleteNewsContentByContentIds(contentIds));
    }
}

